//
//  ViewController.m
//  Orderfood
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property (nonatomic,strong) NSArray *leftlist;
@property (nonatomic,strong) NSArray *rightlist;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.leftlist = @[@"火鸡",@"花生酱",@"金枪鱼沙拉",@"鸡丁沙拉",@"烤牛肉",@"蔬菜",@"土豆泥",@"水果时令",@"奥尔良风味披萨"];
    self.rightlist = @[@"白面包",@"粗面粉面包",@"黑麦面包",@"酸面包",@"天然有机谷",@"奶酪",@"起司蛋糕"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnPressed:(id)sender
{
    int sel1 = [self.pickerView selectedRowInComponent:0];
    int sel2 = [self.pickerView selectedRowInComponent:1];
    NSString *str = [NSString stringWithFormat:@"%@和%@",self.leftlist[sel1],self.rightlist[sel2]];
    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"我要点" message:str delegate:nil cancelButtonTitle:@"重新选择" otherButtonTitles:@"确定", nil];
    [alertView show];
    self.infolabel.text = alertView.message;
    
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == 0)
    {
        return self.leftlist.count;
    }
    else
    {
        return self.rightlist.count;
    }
}

- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0)
    {
        return self.leftlist[row];
    }
    else
    {
        return self.rightlist[row];
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component == 0)
    {
        NSLog(@"您当前选择了%@",self.leftlist[row]);
    }
    else
    {
        NSLog(@"您当前选择了%@",self.rightlist[row]);
    }
}
@end
